<?php
// +----------------------------------------------------------------------
// | EtrolPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Author: LJQ <245369209@qq.com> 
// +----------------------------------------------------------------------

namespace app\basic\model;
use app\common\model\Base;

/**
 * 物资装备
 */
class Equipe extends Base{

	protected $name = "equipmentmaterial";
	protected $createTime = 'createTime';
	protected $updateTime = 'updateTime';

	public function getUnitList() {
		$unitList = db('basicinfo')->where('sysCode',7)->column('subsystemName','subsystemNo');
		return $unitList;
	}
	
	public function getTypeList($id = null){
		$where['sysCode'] = 22 ;
		if($id){
			$where['parentSubsystemNo'] = $id;
		}
		$typeList = db('basicinfo')->where($where)->column('subsystemName','subsystemNo');
		return $typeList;
	}
	
	public function getUnitIdAttr($value,$data) {
		$unitList = $this->getUnitList();
		if($data['unitId']){
			return $unitList[$data['unitId']];
		}
		return null;
	}
	
	public function getTypeIdAttr($value,$data){
		$typeList = $this->getTypeList($data['categoryId']);
		if($data['typeId']){
			return $typeList[$data['typeId']]; 
		}
		return null;
	}
	
	public function enterprise(){

	    return $this->hasOne('enterprise','id','enterpriseId');
	}
	
	public function store() {
		return $this->hasOne('store','id','storeId');
	}
}